package cn.tedu.backend.portal.controller;

import cn.tedu.backend.portal.model.User;
import cn.tedu.backend.portal.service.IUserService;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@Slf4j
public class UserController {
    @Resource
    private IUserService userService;


    @RequestMapping("/userlist")
    public PageInfo<User> list(Integer pageNum){
        //分页
        if (pageNum==null)
            pageNum=1;
        Integer pageSize=10;
        //添加翻页page参数   ↓↓↓↓↓↓↓↓
        PageInfo<User> pageInfo = userService.getUsers(pageNum,pageSize);

        return pageInfo;

    }

    @RequestMapping("/deleteUserById")
    public int deleteByUserId(String userId){
        return userService.deleteByUserId(userId);
    }

    @RequestMapping("/selectNicknameByUserId")
    public String selectNicknameByUserId(String userId){
        System.out.println(userService.selectNicknameByUserId(userId));
        return userService.selectNicknameByUserId(userId);
    }

//    @RequestMapping("/selectNicknameByUserId")
//    public String selectNicknameByUserId(){
//        System.out.println(userService.selectNicknameByUserId());
//        return userService.selectNicknameByUserId();
//    }

    @RequestMapping("/selectUserCount")
    public int selectCount(){
        return userService.selectCount();
    }

    @RequestMapping("/selectVipCount")
    public int selectVipCount(){
        return userService.selectVipCount();
    }

    @RequestMapping("/selectNormalCount")
    public int selectNormalCount(){
        return userService.selectNormalCount();
    }
}
